package com.vhall.component.service.lottery;


import com.vhall.component.entity.interactive.vo.QuestionPageRspVO;
import com.vhall.component.entity.sign.vo.SignRecordPageVO;
import com.vhall.component.plugin.core.service.PaasService;
import com.vhall.component.service.interactive.QuestionService;
import com.vhall.component.service.sign.service.SignInnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;

/**
 * AsyncTask
 *
 * @author update
 */
@Service
public class AsyncTask {

    @Autowired
    private PaasService paasService;

    @Autowired
    private SignInnerService signInnerService;
    @Autowired
    private QuestionService questionService;

    /**
     * 异步获取在线用户列表（请求paas服务）
     */
    @Async("taskExecutor")
    public Future<List<Integer>> getOnlineUsersFromPaas(Integer pos, Integer limit, String channelId) {
        return new AsyncResult<>(paasService.getUserIdList(channelId, pos, limit));
    }


    /**
     * 异步获取签到用户列表
     */
    @Async("taskExecutor")
    public Future<SignRecordPageVO<Integer>> getSignUsersAfterStartLive(Integer pos, Integer limit, String roomId, String startLiveDateTime) {
        return new AsyncResult<>(signInnerService.selectSignAfterLiveStart(roomId, startLiveDateTime, pos, limit, false));
    }

    /**
     * 异步获取问卷用户列表
     */
    @Async("taskExecutor")
    public Future<QuestionPageRspVO<Integer>> getQuestUsersAfterStartLive(Integer pos, Integer limit, String roomId, String startLiveDateTime) {
        return new AsyncResult<>(questionService.queryQuesAccounts(roomId, startLiveDateTime, pos, limit, false));
    }

    @Async("taskExecutor")
    public Future<Map<String, Object>> checkUserStatus(String channelId, List<Integer> ids) {
        return new AsyncResult<>(paasService.checkUserOnlineByChannel(channelId, ids));
    }


}
